package com.zpark.resume.config;

import com.zpark.resume.interceptor.MemberNotLoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

/**
 * @PackageName: com.zpark.resume.config
 * @ClassName: UserNotLoginInterceptorConfig
 * @Description:
 * @author: RZS
 * @date: 2023/6/8  17:22
 */
@Configuration
public class UserNotLoginInterceptorConfig implements WebMvcConfigurer {

    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 实例化拦截器对象
        MemberNotLoginInterceptor loginInterceptor = new MemberNotLoginInterceptor();
        // 获取拦截器注册对象
        InterceptorRegistration registration = registry.addInterceptor(loginInterceptor);
        // 添加拦截路径
        registration.addPathPatterns("/**");
        // 添加不拦截路径
        List<String> whitePath = new ArrayList<>();
        whitePath.add("/css/**");
        whitePath.add("/ele/**");
        whitePath.add("/fonts/**");
        whitePath.add("/image/**");
        whitePath.add("/js/**");
        whitePath.add("/index.html");
        whitePath.add("/register.html");

        whitePath.add("/member/login");
        whitePath.add("/member/reg");

        whitePath.add("/file/upload");

        registration.excludePathPatterns(whitePath);
    }
}
